/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.service.broadcast;

import com.thienloc.omap.entity.BroadcastConfig;
import com.thienloc.omap.util.Constant;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.Socket;
import java.util.Properties;
import java.util.concurrent.ScheduledExecutorService;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
public class BroadcastUnit {

    private ScheduledExecutorService executorService;
    private Socket socket;
    private BroadcastConfig config;

    public BroadcastUnit(BroadcastConfig config) throws IOException {
        this.config = config;

        Properties properties = new Properties();
        File file = new File(Constant.CONFIG_FOLDER + Constant.CONFIG_FILE_NAME);
        properties.load(new FileReader(file));
        String host = properties.getProperty("broadcast.server.host", "localhost");
        int port = Integer.parseInt(properties.getProperty("broadcast.server.port", "15000"));
        this.socket = new Socket(host, port);
        LoggerFactory.getLogger(BroadcastUnit.class.getName()).info("Connected to: {0}:{1}", new Object[]{host, port});
    }

    public ScheduledExecutorService getExecutorService() {
        return executorService;
    }

    public void setExecutorService(ScheduledExecutorService executorService) {
        this.executorService = executorService;
    }

    public Socket getSocket() {
        return socket;
    }

    public void setSocket(Socket socket) {
        this.socket = socket;
    }

    public BroadcastConfig getConfig() {
        return config;
    }
}
